package com.kafka.kafka.study;

import com.kafka.kafka.utils.PropertiesUtils;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.util.Properties;

/**
 * Project: tobe-better-coder
 * Package: com.kafka.kafka.study
 *
 * @author : Mr.xu
 * @date : 2023/9/10 14:53
 */
public class CustomProducerParameters {

    public static void main(String[] args) {
        //1.创建配置
        Properties properties = PropertiesUtils.getKafkaProperties("node1:9092,node2:9092");

        //设置缓冲区
        properties.put(ProducerConfig.BUFFER_MEMORY_CONFIG,33554432);
        //设置分区大小
        properties.put(ProducerConfig.BATCH_SIZE_CONFIG,16384);
        //延迟时间 默认是0
        properties.put(ProducerConfig.LINGER_MS_CONFIG,1000*10);
        //压缩
        properties.put(ProducerConfig.COMPRESSION_TYPE_CONFIG,"snappy");
        //创建kafka生产者对象
        KafkaProducer<String,String> kafkaProducer = new KafkaProducer<>(properties);
        //发送消息
        kafkaProducer.send(new ProducerRecord<>("kafka","hello kafka222"));



        kafkaProducer.close();

    }
}